using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class AddressMap : EntityTypeConfiguration<Address>
	{
		public AddressMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.ZipCode)
				.HasMaxLength(10);
				
			this.Property(t => t.State)
				.HasMaxLength(100);
				
			this.Property(t => t.AddressDesc)
				.IsRequired()
				.HasMaxLength(255);
				
			this.Property(t => t.PhoneNumber)
				.HasMaxLength(20);
				
			this.Property(t => t.Fax)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("Addresses");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.PatientId).HasColumnName("PatientId");
			this.Property(t => t.PatientRelativeId).HasColumnName("PatientRelativeId");
			this.Property(t => t.BankId).HasColumnName("BankId");
			this.Property(t => t.SupplierId).HasColumnName("SupplierId");
			this.Property(t => t.DoctorExtId).HasColumnName("DoctorExtId");
			this.Property(t => t.HospitalId).HasColumnName("HospitalId");
			this.Property(t => t.InsuranceId).HasColumnName("InsuranceId");
			this.Property(t => t.TypeId).HasColumnName("TypeId");
			this.Property(t => t.CountryId).HasColumnName("CountryId");
			this.Property(t => t.ProvinceId).HasColumnName("ProvinceId");
			this.Property(t => t.ZipCode).HasColumnName("ZipCode");
			this.Property(t => t.State).HasColumnName("State");
			this.Property(t => t.AreaId).HasColumnName("AreaId");
			this.Property(t => t.AddressDesc).HasColumnName("AddressDesc");
			this.Property(t => t.CityId).HasColumnName("CityId");
			this.Property(t => t.PhoneNumber).HasColumnName("PhoneNumber");
			this.Property(t => t.RecordStatus).HasColumnName("RecordStatus");
			this.Property(t => t.Fax).HasColumnName("Fax");

			// Relationships
			this.HasOptional(t => t.Bank)
				.WithMany(t => t.Addresses)
				.HasForeignKey(d => d.BankId);
				
			this.HasOptional(t => t.DoctorExt)
				.WithMany(t => t.Addresses)
				.HasForeignKey(d => d.DoctorExtId);
				
			this.HasOptional(t => t.Insurance)
				.WithMany(t => t.Addresses)
				.HasForeignKey(d => d.InsuranceId);
				
			this.HasOptional(t => t.PatientRelative)
				.WithMany(t => t.Addresses)
				.HasForeignKey(d => d.PatientRelativeId);
				
			this.HasOptional(t => t.Patient)
				.WithMany(t => t.Addresses)
				.HasForeignKey(d => d.PatientId);
				
			this.HasOptional(t => t.RefHu)
				.WithMany(t => t.Addresses)
				.HasForeignKey(d => d.HospitalId);
				
			this.HasOptional(t => t.Supplier)
				.WithMany(t => t.Addresses)
				.HasForeignKey(d => d.SupplierId);
				
		}
	}
}

